using System.Drawing;
using System;
using DevExpress.XtraGauges.Win.Gauges.Circular;
using DevExpress.XtraGauges.Core.Model;
using DevExpress.DXperience.Demos;

namespace LPV.Gauges
{
    public partial class AnalogClock : TutorialControlBase//TutorialControl
    {
        private System.Windows.Forms.Timer timer1;
        private System.ComponentModel.IContainer components;
        private DevExpress.XtraGauges.Win.GaugeControl gaugeControl1;
        private DevExpress.XtraGauges.Win.Gauges.Circular.CircularGauge circularGauge1;
        private DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleBackgroundLayerComponent arcScaleBackgroundLayerComponent1;
        private DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleComponent scaleHours;
        private DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleNeedleComponent arcScaleNeedleComponent1;
        private DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleNeedleComponent arcScaleNeedleComponent2;

        ArcScaleComponent scaleMinutes, scaleSeconds;
        private ArcScaleSpindleCapComponent arcScaleSpindleCapComponent1;
        private ArcScaleEffectLayerComponent arcScaleEffectLayerComponent1;
        private ArcScaleNeedleComponent arcScaleNeedleComponent3;
        
        public AnalogClock()
        {
            InitializeComponent();
            scaleMinutes = circularGauge1.AddScale();
            scaleSeconds = circularGauge1.AddScale();

            scaleMinutes.Assign(scaleHours);
            scaleSeconds.Assign(scaleHours);

            arcScaleNeedleComponent2.ArcScale = scaleMinutes;
            arcScaleNeedleComponent3.ArcScale = scaleSeconds;
            timer1.Start();
            //OnTimerTick(null, null);
        }
        
        #region "   InitializeComponent"
        private void InitializeComponent() 
        {
            this.components = new System.ComponentModel.Container();
            DevExpress.XtraGauges.Core.Drawing.SolidBrushObject solidBrushObject1 = new DevExpress.XtraGauges.Core.Drawing.SolidBrushObject();
            DevExpress.XtraGauges.Core.Drawing.StyleShader styleShader1 = new DevExpress.XtraGauges.Core.Drawing.StyleShader();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.gaugeControl1 = new DevExpress.XtraGauges.Win.GaugeControl();
            this.circularGauge1 = new DevExpress.XtraGauges.Win.Gauges.Circular.CircularGauge();
            this.arcScaleBackgroundLayerComponent1 = new DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleBackgroundLayerComponent();
            this.scaleHours = new DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleComponent();
            this.arcScaleEffectLayerComponent1 = new DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleEffectLayerComponent();
            this.arcScaleNeedleComponent1 = new DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleNeedleComponent();
            this.arcScaleNeedleComponent2 = new DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleNeedleComponent();
            this.arcScaleNeedleComponent3 = new DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleNeedleComponent();
            this.arcScaleSpindleCapComponent1 = new DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleSpindleCapComponent();
            ((System.ComponentModel.ISupportInitialize)(this.circularGauge1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.arcScaleBackgroundLayerComponent1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.scaleHours)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.arcScaleEffectLayerComponent1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.arcScaleNeedleComponent1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.arcScaleNeedleComponent2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.arcScaleNeedleComponent3)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.arcScaleSpindleCapComponent1)).BeginInit();
            this.SuspendLayout();
            // 
            // timer1
            // 
            this.timer1.Tick += new System.EventHandler(this.OnTimerTick);
            // 
            // gaugeControl1
            // 
            this.gaugeControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.gaugeControl1.Gauges.AddRange(new DevExpress.XtraGauges.Win.Base.GaugeBase[] {
            this.circularGauge1});
            this.gaugeControl1.Location = new System.Drawing.Point(0, 0);
            this.gaugeControl1.Name = "gaugeControl1";
            this.gaugeControl1.Size = new System.Drawing.Size(528, 523);
            this.gaugeControl1.TabIndex = 0;
            // 
            // circularGauge1
            // 
            this.circularGauge1.BackgroundLayers.AddRange(new DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleBackgroundLayerComponent[] {
            this.arcScaleBackgroundLayerComponent1});
            this.circularGauge1.Bounds = new System.Drawing.Rectangle(6, 6, 516, 511);
            this.circularGauge1.EffectLayers.AddRange(new DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleEffectLayerComponent[] {
            this.arcScaleEffectLayerComponent1});
            this.circularGauge1.Needles.AddRange(new DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleNeedleComponent[] {
            this.arcScaleNeedleComponent1,
            this.arcScaleNeedleComponent2,
            this.arcScaleNeedleComponent3});
            this.circularGauge1.Scales.AddRange(new DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleComponent[] {
            this.scaleHours});
            this.circularGauge1.SpindleCaps.AddRange(new DevExpress.XtraGauges.Win.Gauges.Circular.ArcScaleSpindleCapComponent[] {
            this.arcScaleSpindleCapComponent1});
            // 
            // arcScaleBackgroundLayerComponent1
            // 
            this.arcScaleBackgroundLayerComponent1.ArcScale = this.scaleHours;
            this.arcScaleBackgroundLayerComponent1.Name = "arcScaleBackgroundLayerComponent1";
            this.arcScaleBackgroundLayerComponent1.ShapeType = DevExpress.XtraGauges.Core.Model.BackgroundLayerShapeType.CircularFull_Clock;
            this.arcScaleBackgroundLayerComponent1.Size = new System.Drawing.SizeF(33F, 33F);
            this.arcScaleBackgroundLayerComponent1.ZOrder = 1000;
            // 
            // scaleHours
            // 
            this.scaleHours.AppearanceTickmarkText.Font = new System.Drawing.Font("Tahoma", 11F);
            solidBrushObject1.Color = System.Drawing.Color.Black;
            this.scaleHours.AppearanceTickmarkText.TextBrush = solidBrushObject1;
            this.scaleHours.Center = new DevExpress.XtraGauges.Core.Base.PointF2D(125F, 125F);
            this.scaleHours.EndAngle = 270F;
            this.scaleHours.MajorTickCount = 13;
            this.scaleHours.MajorTickmark.FormatString = "{0:F0}";
            this.scaleHours.MajorTickmark.ShapeOffset = -4F;
            this.scaleHours.MajorTickmark.ShapeType = DevExpress.XtraGauges.Core.Model.TickmarkShapeType.Circular_Style10_2;
            this.scaleHours.MajorTickmark.ShowFirst = false;
            this.scaleHours.MajorTickmark.TextOffset = -15F;
            this.scaleHours.MajorTickmark.TextOrientation = DevExpress.XtraGauges.Core.Model.LabelOrientation.LeftToRight;
            this.scaleHours.MaxValue = 12F;
            this.scaleHours.MinorTickCount = 4;
            this.scaleHours.MinorTickmark.ShapeOffset = -0.5F;
            this.scaleHours.MinorTickmark.ShapeType = DevExpress.XtraGauges.Core.Model.TickmarkShapeType.Circular_Style10_1;
            this.scaleHours.Name = "scaleHours";
            this.scaleHours.RadiusX = 90F;
            this.scaleHours.RadiusY = 90F;
            styleShader1.StyleColor1 = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            styleShader1.StyleColor2 = System.Drawing.Color.Gray;
            this.scaleHours.Shader = styleShader1;
            this.scaleHours.StartAngle = -90F;
            // 
            // arcScaleEffectLayerComponent1
            // 
            this.arcScaleEffectLayerComponent1.ArcScale = this.scaleHours;
            this.arcScaleEffectLayerComponent1.Name = "arcScaleEffectLayerComponent1";
            this.arcScaleEffectLayerComponent1.ScaleCenterPos = new DevExpress.XtraGauges.Core.Base.PointF2D(0.5F, 1F);
            this.arcScaleEffectLayerComponent1.ShapeType = DevExpress.XtraGauges.Core.Model.EffectLayerShapeType.CircularFull_Clock;
            this.arcScaleEffectLayerComponent1.Size = new System.Drawing.SizeF(210F, 105F);
            this.arcScaleEffectLayerComponent1.ZOrder = -1000;
            // 
            // arcScaleNeedleComponent1
            // 
            this.arcScaleNeedleComponent1.ArcScale = this.scaleHours;
            this.arcScaleNeedleComponent1.EndOffset = 20F;
            this.arcScaleNeedleComponent1.Name = "arcScaleNeedleComponent1";
            this.arcScaleNeedleComponent1.ShapeType = DevExpress.XtraGauges.Core.Model.NeedleShapeType.CircularFull_ClockHour;
            this.arcScaleNeedleComponent1.ZOrder = -50;
            // 
            // arcScaleNeedleComponent2
            // 
            this.arcScaleNeedleComponent2.ArcScale = this.scaleHours;
            this.arcScaleNeedleComponent2.Name = "arcScaleNeedleComponent2";
            this.arcScaleNeedleComponent2.ShapeType = DevExpress.XtraGauges.Core.Model.NeedleShapeType.CircularFull_ClockMinute;
            this.arcScaleNeedleComponent2.ZOrder = -49;
            // 
            // arcScaleNeedleComponent3
            // 
            this.arcScaleNeedleComponent3.ArcScale = this.scaleHours;
            this.arcScaleNeedleComponent3.EndOffset = -10F;
            this.arcScaleNeedleComponent3.Name = "arcScaleNeedleComponent3";
            this.arcScaleNeedleComponent3.ShapeType = DevExpress.XtraGauges.Core.Model.NeedleShapeType.CircularFull_ClockSecond;
            this.arcScaleNeedleComponent3.ZOrder = -101;
            // 
            // arcScaleSpindleCapComponent1
            // 
            this.arcScaleSpindleCapComponent1.ArcScale = this.scaleHours;
            this.arcScaleSpindleCapComponent1.Name = "arcScaleSpindleCapComponent1";
            this.arcScaleSpindleCapComponent1.ShapeType = DevExpress.XtraGauges.Core.Model.SpindleCapShapeType.CircularFull_Clock;
            this.arcScaleSpindleCapComponent1.Size = new System.Drawing.SizeF(20F, 20F);
            this.arcScaleSpindleCapComponent1.ZOrder = -100;
            // 
            // AnalogClock
            // 
            this.Controls.Add(this.gaugeControl1);
            this.Name = "AnalogClock";
            this.Size = new System.Drawing.Size(528, 523);
            ((System.ComponentModel.ISupportInitialize)(this.circularGauge1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.arcScaleBackgroundLayerComponent1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.scaleHours)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.arcScaleEffectLayerComponent1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.arcScaleNeedleComponent1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.arcScaleNeedleComponent2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.arcScaleNeedleComponent3)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.arcScaleSpindleCapComponent1)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

        void OnTimerTick(object sender, System.EventArgs e)
        {
            UpdateClock(Variable.ngay_gio_hienhanh.AddSeconds(-0.5), scaleHours, scaleMinutes, scaleSeconds);
        }
        
        void UpdateClock(DateTime dt, IArcScale h, IArcScale m, IArcScale s) 
        {
            int hour = dt.Hour <= 12 ? dt.Hour : dt.Hour - 12;
            int min = dt.Minute;
            int sec = dt.Second;
            h.Value = (float)hour + (float)(min) / 60.0f;
            m.Value = ((float)min + (float)(sec) / 60.0f) / 5f;
            s.Value = sec / 5.0f;
        }


    }
}
